<?php

namespace Plu\qdh\Services;

use Httpful\Request;
use Plu\qdh\Services\ServiceBase;
use Plu\qdh\Models\App\Project;
use Plu\qdh\Models\App\Platform;
use Plu\qdh\Models\App\Order;
use Plu\qdh\Services\ThirdService;
use Plu\qdh\Models\App\Product;

class AdminService extends ServiceBase {

    public function getOrders($limit, $offset, $search) {
        list($count, $items) = Order::gerItems($limit, $offset, $search);
        if ($count > 0) {
            foreach ($items as $index => $item) {
                $items[$index]['createTime']    = date('Y-m-d H:i:s', $item['createTime']);
                $items[$index]['travelDay']     = date('Y-m-d', $item['travelDay']);
                $items[$index]['payTime']       = $item['payTime']?date('Y-m-d H:i:s', $item['payTime']):"";
                $items[$index]['updateTime']    = date('Y-m-d H:i:s', $item['updateTime']);
                $items[$index]['total']         = $items[$index]['price'] * $items[$index]['num'];
            }
        }
        return [$count, $items];
    }


    public function applyRefindOrder($orderId) {
        $thirdService = new ThirdService;
        $reFindApply  = $thirdService->reFindOrder($orderId);
        if ($reFindApply) {
            $orderInfo = Order::getItemByOrderId($orderId);
            $orderInfo->status = \OrderConst::ORDER_STATUS['refoundConfirming'];
            $orderInfo->save();
            return [
                'code' => 1,
                'msg'  => 'success'
            ];
        }
        return [
            'code' => 0,
            'msg'  => $reFindApply->getErrMsg()
        ];
    }

    public function rejectCancelOrder($orderId) {
        $order = Order::getItemByOrderId($orderId);
        $order->status = \OrderConst::ORDER_STATUS['refoundRejected'];
        $order->save();
        return [
            'code' => 1,
            'msg'  => 'success'
        ];
    }



}